package pack0707;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemoA {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();

        map.put("a", "aaaaa");
        map.put("b", "bbbbb");
        map.put("c", "ccccc");
        map.put("d", "ddddd");
        map.put("e", "eeeee");

        System.out.println(map);
        System.out.println(map.size());
        System.out.println(map.get("b"));

        //获取所有的键
        Set<String> keys = map.keySet();
        for (String key : keys) {
            System.out.println(key);
        }

        //获取所有的值
        Collection<String> cols = map.values();
        System.out.println(cols);
 //       System.out.println(cols.getClass());
        for (String col : cols) {
            System.out.println(col);
        }

        //获取所有的键值对
        Set<Map.Entry<String,String>> entries=map.entrySet();

        //foreach循环
        for (Map.Entry<String, String> entry : entries) {
            System.out.println(entry.getKey()+"::"+entry.getValue());
        }

        Map<Person,String> map1=new HashMap<>();

        map1.put(new Person("张无忌",20),"aaaaaaa");
        map1.put(new Person("张无忌",20),"bbbbbbb");
        map1.put(new Person("张无忌",20),"ccccccc");
        map1.put(new Person("张无忌",20),"ddddddd");

        System.out.println(map1);
        System.out.println(new Person("张无忌",20));
        System.out.println(map1.size());
        System.out.println(map1.get(new Person("张无忌",20)));

    }
}
